//
//  BaseViewController.m
//  base
//
//  Created by 吕超 on 17/3/7.
//  Copyright © 2017年 lc. All rights reserved.
//

#import "BaseViewController.h"
#import "MJRefresh.h"
#import "MBProgressHUD.h"
#import "AFNetworking.h"
#import "UIImage+ImageCategory.h"
#import "Tools.h"
// 屏幕宽
#define selfWidth [UIScreen mainScreen].bounds.size.width
// 屏幕高
#define selfHeigh   [UIScreen mainScreen].bounds.size.height


@interface BaseViewController ()

//  加载  等待 动画
@property (nonatomic, strong)MBProgressHUD *HUD;


@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 背景色
    self.view.backgroundColor = [UIColor whiteColor];

    //  从导航栏 计算 位置
    self.edgesForExtendedLayout = UIRectEdgeNone;

    // 导航栏 颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    
    //  导航栏 按钮  颜色
    self.navigationController.navigationBar.tintColor  = [UIColor whiteColor];

    self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    
    _HUD.labelText = @"等待中";
    // 动画 样式
    _HUD.mode = MBProgressHUDModeIndeterminate;
    
    [_HUD show:YES];
    
    [self.view addSubview:_HUD];
}





//  get 请求  数据
- (void)GetRequsetDataUrlString:(NSString *)url Parameters:(NSDictionary *)dic{
    
     __weak typeof(self) WeakSelf = self;

    [Tools GET:url parameters:dic success:^(id  responseObject) {
        
        [WeakSelf.HUD removeFromSuperview];
        
        WeakSelf.GetSuccess(responseObject);
   
    } failure:^(NSError *error) {
        NSLog(@"网络请求失败:%@",error);
    }];
}



// post 请求 数据
- (void)PostRequsetDataUrlString:(NSString *)url Parameters:(NSDictionary *)dic{
    
    __weak typeof(self) WeakSelf = self;
    [Tools POST:url  parameters:dic success:^(id responseObject) {
    
        [WeakSelf.HUD removeFromSuperview];
        
         WeakSelf.PostSuccess(responseObject);
        
    } failure:^(NSError *error) {
        NSLog(@"网络请求失败:%@",error);
    }];
}



//  创建  MJ刷新
- (void)createMJRefresh{
    
    //下拉  刷新
    self.mainTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //开始刷新数据
        [self.mainTableView.mj_header beginRefreshing];
        
        self.judge = 10;
        
        self.header();
    }];
    
    
    
    //上拉   加载
    self.mainTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        //开始刷新数据
        [self.mainTableView.mj_footer beginRefreshing];

        _judge = 11;
        
        self.footer();
    }];
}




#pragma mark ====  添加返回按钮
- (void)AddNavigationRetunItem{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"left_white_arrow"] style:(UIBarButtonItemStylePlain) target:self action:@selector(returnTopView)];
}

- (void)returnTopView{
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark  ====   懒加载
- (UITableView *)mainTableView{
    if (_mainTableView == nil){
        // 全屏  特殊情况在修改  设置从导航栏底部开始计算
        _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,selfWidth , selfHeigh - 64)];
        //隐藏cell线
        _mainTableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
        // 隐藏滑动条
        _mainTableView.showsVerticalScrollIndicator = NO;
        // tableView多余cell空白
        _mainTableView.tableFooterView = [[UIView alloc]init];
    }
    return _mainTableView;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
